package com.nidu.demo.web.system;

import com.alibaba.cola.dto.PageResponse;
import com.alibaba.cola.dto.SingleResponse;
import com.nidu.demo.log.api.SysLoginLogService;
import com.nidu.demo.online.api.OnlineUserService;
import com.nidu.demo.online.dto.OnlineUserDetailCO;
import com.nidu.demo.online.dto.OnlineUserPageQry;
import com.nidu.demo.online.dto.OnlineUserStatisticsCO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 登录日志管理
 *
 * @author auto
 */
@Tag(name = "管理后台 - 在线用户")
@RestController
@RequestMapping("/system/online")
@Validated
@RequiredArgsConstructor
public class SysOnlineController {

    private final OnlineUserService onlineUserService;

    @Operation(summary = "获取在线用户统计", description = "获取当前在线用户统计信息")
    @GetMapping("/statistics")
    @PreAuthorize("@ss.hasPermission('system:login-log:query')")
    public SingleResponse<OnlineUserStatisticsCO> getOnlineUserStatistics() {
        return onlineUserService.getOnlineUserStatistics();
    }

    @Operation(summary = "分页查询在线用户", description = "分页获取当前在线用户信息")
    @GetMapping("/users")
    @PreAuthorize("@ss.hasPermission('system:login-log:query')")
    public PageResponse<OnlineUserDetailCO> pageOnlineUsers(OnlineUserPageQry qry) {
        return onlineUserService.pageOnlineUsers(qry);
    }
}
